package com.neuedu.jdbc.v3.dao;

import com.neuedu.jdbc.v3.DBUtils;
import com.neuedu.jdbc.v3.entity.Account;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AccountDao  {
    public int updateById(Connection  conn ,Account account){
        String sql = " update account set amount = ? where id  = ?";

            int count = 0;

            PreparedStatement stmt = null;
            try {
//                conn = DBUtils.getConnection();
                stmt = conn.prepareStatement(sql.toString());

                //绑定变量
                stmt.setDouble(1, account.getAmount());
                stmt.setInt(2, account.getId());

                count = stmt.executeUpdate();

            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                //关闭资源
                DBUtils.close(null, stmt, null);
            }
            return count;
    }
}
